package def;

import java.io.PrintStream;
import java.util.Hashtable;

public abstract class Argument {
	
	public TSpan tspan = null;
	
	public void setTspan(TSpan tspan) {
		this.tspan = tspan;
	}

	public TSpan getTspan() {
		return tspan;
	}
	
	static Hashtable<String, Argument> argsInDoc = new Hashtable<String, Argument>();

	public static void debugPrintArgs(PrintStream stream){
		stream.println(argsInDoc);
	}
	
	public static Argument find(String id){
//		if (argsInDoc.containsKey(id))
			return argsInDoc.get(id);
	}
	
	public static void clear(){
		argsInDoc.clear();
	}
	
	public abstract String getId()  ;
	// parse a line into an argument
	public static Argument parse(String line){
		Argument arg = null;
		if (line.startsWith("T")){
			TSpan ts = new TSpan();
			ts.parse(line);
			if (ts.textType == TextType.Protein){
				arg = new Protein();
				arg.setTspan(ts);
				argsInDoc.put(arg.getId(), arg);
			}
			else if (ts.textType == TextType.Entity){
				arg = new Entity();
				arg.setTspan(ts);
				argsInDoc.put(arg.getId(), arg);
			}
			else{
				arg = new Event();
				arg.setTspan(ts);
//				System.err.println("reading... "+ts);
				argsInDoc.put(ts.tid, arg);
			}
		}
		else if (line.startsWith("M") || line.startsWith("*")){
			// TODO
		}
		else if (line.startsWith("E")){
			arg = new Event();
			arg.parseLine(line);
			argsInDoc.put(arg.getId(), arg);
			if (argsInDoc.containsKey(((Event)arg).tid))
				((Event)arg).merge((Event)argsInDoc.get(((Event)arg).tid));
		}
		else{
			System.err.println("Argument.parse goes nowhere!\n"+"TEXT : "+line);
		}
		return arg;
	}
	
	public void parseLine(String line){
		
	}
	
}
